package cn.lingyangwl.agile.pay.mch.controller.order;

import cn.lingyangwl.framework.core.response.Resp;
import cn.lingyangwl.agile.common.core.exception.enums.GlobalErrorEnum;
import cn.lingyangwl.agile.pay.model.entity.TransferOrder;
import cn.lingyangwl.agile.pay.model.rqrs.TransferOrderQL;
import cn.lingyangwl.agile.pay.common.service.TransferOrderService;
import cn.lingyangwl.agile.ram.ActionType;
import cn.lingyangwl.agile.ram.RamResource;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 转账订单api
 *
 * @author shenguangyang
 */
@RestController(value = "mgrTransferOrderController")
@RequestMapping("/transfer")
public class TransferOrderController {
    @Resource
    private TransferOrderService transferOrderService;

    @GetMapping(value="/pageTransferOrder")
    @RamResource(action = "pay:transferOrder:list", name = "查询转账订单列表", type = ActionType.READ)
    public Resp<IPage<TransferOrder>> page(TransferOrderQL query) {
        IPage<TransferOrder> pages = transferOrderService.pageTransferOrder(query);
        return Resp.ok(pages);
    }

    @GetMapping(value="/getTransferOrder")
    @RamResource(action = "pay:transferOrder:get", name = "查询转账订单详情", type = ActionType.READ)
    public Resp<TransferOrder> getTransferOrder(@RequestParam("recordId") String transferNo) {
        TransferOrder refundOrder = transferOrderService.getById(transferNo);
        if (refundOrder == null) {
            return Resp.fail(GlobalErrorEnum.OPERATION_FAIL_SELETE);
        }
        return Resp.ok(refundOrder);
    }
}
